﻿'
' Boogaloo® - http://www.mindfly.com
' Copyright (c) 2009
' by Mindfly, Inc.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
' WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Imports System.Data.SqlClient
Imports Boogaloo.Base.DAL

Namespace DAL.SqlClient

    Public Class SqlPingServiceDataProvider
        Inherits PingServiceDataProvider

#Region "Ping Service"


        ''' <summary>
        ''' Creates a PingService Details from database record
        ''' </summary>
        ''' <param name="ping_service_id">Integer (PK)</param>
        ''' <returns>PingServiceDetails</returns>
        ''' <remark>rss - 4/19/2009</remark>
        Public Overrides Function GetPingService(ByVal ping_service_id As Integer) As PingServiceDetails
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("boogaloo_core_pingservice_GetPingService_sp", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@ping_service_id", SqlDbType.Int).Value = ping_service_id
                cn.Open()
                Dim reader As SqlDataReader = ExecuteReader(cmd)
                If reader.Read Then
                    Return GetPingServiceDetailsFromReader(reader)
                Else
                    Return Nothing
                End If
            End Using
        End Function

        ''' <summary>
        ''' Creates a collection of PingServiceDetails from a database recordset
        ''' </summary>
        ''' <returns>List(Of PingServiceDetails)</returns>
        ''' <remark>rss - 4/19/2009</remark>
        Public Overrides Function GetPingServices() As List(Of PingServiceDetails)
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("boogaloo_core_pingservice_GetPingServices_sp", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cn.Open()
                Return GetPingServiceDetailsCollectionFromReader(ExecuteReader(cmd))
            End Using
        End Function

        ''' <summary>
        ''' Inserts a record representing an PingServiceDetails into the database
        ''' </summary>
        ''' <returns>Integer (PK of record inserted)</returns>
        ''' <remark>rss - 4/19/2009</remark>
        Public Overrides Function InsertPingService(ByVal record As PingServiceDetails) As Integer
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("boogaloo_core_pingservice_InsertPingService_sp", cn)
                cmd.CommandType = CommandType.StoredProcedure
                With cmd.Parameters
                    .Add("@uri", SqlDbType.NVarChar, 255).Value = record.uri
                    .Add("@last_modified_by", SqlDbType.NVarChar, 50).Value = record.last_modified_by
                    .Add("@ping_service_id", SqlDbType.Int).Direction = ParameterDirection.Output
                End With
                cn.Open()
                Dim ret As Integer = ExecuteNonQuery(cmd)
                Return CInt(cmd.Parameters("@ping_service_id").Value)
            End Using
        End Function

        ''' <summary>
        ''' Updates an existing PingServiceDetails record in the database
        ''' </summary>
        ''' <returns>Boolean (success)</returns>
        ''' <remark>rss - 4/19/2009</remark>
        Public Overrides Function UpdatePingService(ByVal record As PingServiceDetails) As Boolean
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("boogaloo_core_pingservice_UpdatePingService_sp", cn)
                cmd.CommandType = CommandType.StoredProcedure
                With cmd.Parameters
                    .Add("@ping_service_id", SqlDbType.Int).Value = record.ping_service_id
                    .Add("@uri", SqlDbType.NVarChar, 50).Value = record.uri
                    .Add("@last_modified_by", SqlDbType.NVarChar, 50).Value = record.last_modified_by
                End With
                cn.Open()
                Return ExecuteNonQuery(cmd) = 1
            End Using
        End Function

        ''' <summary>
        ''' Deletes an existing PingServiceDetails record from the database
        ''' </summary>
        ''' <returns>Boolean (success)</returns>
        ''' <remark>rss - 4/19/2009</remark>
        Public Overrides Function DeletePingService(ByVal ping_service_id As Integer) As Boolean
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("boogaloo_core_pingservice_DeletePingService_sp", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@ping_service_id", SqlDbType.Int).Value = ping_service_id
                cn.Open()
                Return ExecuteNonQuery(cmd) = 1
            End Using
        End Function


#End Region


    End Class


End Namespace